<?php

/**
 * @Author:             wuchenge
 * @Date:               2025-03-04 20:32:28
 * @Last Modified by:   wuchenge
 */
namespace App\Models;

use App\Models\Model;

class UserInfo extends Model
{
    /**
     * @var array
     */
    protected $fillable = ['user_id', 'nick_name', 'avatar', 'telegram',
        'levels', 'points'];

    /**
     * @var array
     */
    protected $guarded = ['created_at', 'updated_at'];

    /**
     * @var string
     */
    protected $table = 'user_info';

    /**
     * @return mixed
     */
    public function level()
    {
        return $this->belongsTo(Level::class, 'levels', 'id');
    }

    /**
     * 图片
     * @param [type] $value [description]
     */
    public function setAvatar($value)
    {
        if (!empty($value)) {
            $url                        = config('app.url');
            $this->attributes['avatar'] = ltrim(str_replace($url, '', $value),
                '/');
        }
    }

    /**
     * @param $value
     * @return mixed
     */
    public function getAvatar($value)
    {
        if (!empty($value)) {
            $value = url($value);
        }

        return $value;
    }

}
